package cranix.common.util;

import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;

public class SetCharacterEncodingFilter implements Filter {

	@SuppressWarnings("unused")
	private FilterConfig m_config = null;
	private String m_encoding = "MS949";
	
	public void init(FilterConfig config) throws ServletException {
		m_config   = config;
		m_encoding = config.getInitParameter("encoding");
		System.out.println("EncodingFilter.init().... " + m_encoding);
	}
	
	public  void doFilter(ServletRequest srequest, ServletResponse  sresponse, FilterChain chain) throws IOException, ServletException {
		HttpServletRequest request = (HttpServletRequest)srequest;
		request.setCharacterEncoding(m_encoding);
		//System.out.println("EncodingFilter.doFilter().... " + request.getRequestURI()+":"+request.getCharacterEncoding());
		// move on to the next
		chain.doFilter(srequest, sresponse);
	}
	
	public void destroy() {
		m_config = null;
		m_encoding = null;
	}
}
